package com.cyt.web.controller.work.wxassociationnewstu;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.util.EasyPoiUtil;
import com.cyt.work.association.model.vo.WxAssociationSignVo;
import com.cyt.work.association.model.vo.WxAssociationNewStuExportVo;
import com.cyt.work.association.model.vo.WxAssociationNewStuVo;
import com.cyt.work.association.service.WxAssociationNewStuService;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 招新对象关联表-招新对象关联表控制层
 *
 * @author han jun
 * @date 2019-9-3 16:43:33
 */
@RestController
public class WxAssociationNewStuController extends BaseController {

    @Resource
    private WxAssociationNewStuService wxAssociationNewStuService;
    
    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @RequestMapping("/work/wxassociationnewstu/wxassociationnewstu/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findPage", method = RequestMethod.POST)
    public ReturnResult findPage(WxAssociationNewStuVo wxAssociationNewStuVo, int page, int limit) {
        return wxAssociationNewStuService.findPage(wxAssociationNewStuVo, page, limit);
    }

    /**
     * 分页查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findVoPage", method = RequestMethod.POST)
    public ReturnResult findVoPage(WxAssociationNewStuVo wxAssociationNewStuVo, int page, int limit) {
        return wxAssociationNewStuService.findVoPage(wxAssociationNewStuVo, page, limit);
    }

    /**
     * 查询该招新已报名人数（对比图）
     *
     * @param wxAssociationSignVo 接受参数对象
     * @param page 分页数
     * @param limit 每页显示条数
     * @return ReturnResult
     * @author ding xu
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "分页查询已报名人数", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findVoHasSignPage", method = RequestMethod.POST)
    public ReturnResult findVoHasSignPage(WxAssociationSignVo wxAssociationSignVo, int page, int limit) {
        return wxAssociationNewStuService.findVoHasSignPage(wxAssociationSignVo, page, limit);
    }

    /**
     * list查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findList", method = RequestMethod.POST)
    public ReturnResult findList(WxAssociationNewStuVo wxAssociationNewStuVo) {
        return new ReturnResult(wxAssociationNewStuService.findList(wxAssociationNewStuVo));
    }

    /**
     * list查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "list查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findVoList", method = RequestMethod.POST)
    public ReturnResult findVoList(WxAssociationNewStuVo wxAssociationNewStuVo) {
        return new ReturnResult(wxAssociationNewStuService.findVoList(wxAssociationNewStuVo));
    }

    /**
     * 单个对象查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findOne", method = RequestMethod.POST)
    public ReturnResult findOne(WxAssociationNewStuVo wxAssociationNewStuVo) {
        return new ReturnResult(wxAssociationNewStuService.findOne(wxAssociationNewStuVo));
    }

    /**
     * 单个对象查询
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "one查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/findVoOne", method = RequestMethod.POST)
    public ReturnResult findVoOne(WxAssociationNewStuVo wxAssociationNewStuVo) {
        return new ReturnResult(wxAssociationNewStuService.findVoOne(wxAssociationNewStuVo));
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(WxAssociationNewStuVo wxAssociationNewStuVo) {
        ModelAndView view = new ModelAndView("/work/wxassociationnewstu/wxassociationnewstu/wxAssociationNewStuEdit");
        if (StringUtils.isNotBlank(wxAssociationNewStuVo.getId())) {
            view.addObject(wxAssociationNewStuService.findVoOne(wxAssociationNewStuVo));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WxAssociationNewStuVo wxAssociationNewStuVo) {
        return wxAssociationNewStuService.addOrUpdate(wxAssociationNewStuVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WxAssociationNewStuVo wxAssociationNewStuVo) {
        return wxAssociationNewStuService.remove(wxAssociationNewStuVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param wxAssociationNewStuVo 接受参数对象
     * @return ReturnResult
     * @author han jun
     * @date 2019-9-3 16:43:33
     */
    @BaseLog(module = "招新对象关联表", classz = "招新对象关联表", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WxAssociationNewStuVo wxAssociationNewStuVo) {
        return wxAssociationNewStuService.delete(wxAssociationNewStuVo, acceptCurrentUser(request));
    }

    /**
     * 导出社团人员
     * @param response
     * @author hanjun
     * @date 2019/9/3 13:43
     */
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/export")
    public void exportExcel(HttpServletResponse response) {
        List<WxAssociationNewStuExportVo> list = new ArrayList<>();
        list.add(new WxAssociationNewStuExportVo("C20150126", "哈军", "1班", "初中一年级","18019933806"));
        list.add(new WxAssociationNewStuExportVo("C20150127", "赵军", "1班", "初中三年级","18019933805"));
        // 导出操作
        EasyPoiUtil.exportExcel(list, "学生信息", "学生信息", WxAssociationNewStuExportVo.class, "学生信息.xls", response);
    }


    /**
     * 导入社团人员，主要需要保存到学校用户表
     * @param file
     * @param request
     * @author hanjun
     * @date 2019/9/3 13:33
     */
    @RequestMapping(value = "/work/wxassociationnewstu/wxassociationnewstu/importExcel", method = RequestMethod.POST)
    public ReturnResult importExcel(MultipartFile file, HttpServletRequest request,String associationNewId,String applyId) {
        return wxAssociationNewStuService.importExcel(file, acceptCurrentUser(request),associationNewId,applyId);
    }





}